using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using SapaFinance.Domain.Model;

namespace SapaFinance.Domain.EntityFramework
{
    internal class OrderConfiguration : EntityTypeConfiguration<Order>
    {
        public OrderConfiguration()
        {
            ToTable(typeof (Order).Name.ToLower());
            HasKey(x => x.UID);
            Property(x => x.UID).HasColumnName("id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(x => x.PaymentPeriod).HasColumnName("paymentperiod").IsRequired();
            Property(x => x.PaymentPurpose).HasColumnName("paymentpurpose").IsRequired();
            HasRequired(p => p.CreatedBy).WithMany().Map(m => m.MapKey("createdbyid")).WillCascadeOnDelete(false);
            HasRequired(p => p.ChangedBy).WithMany().Map(m => m.MapKey("changedbyid")).WillCascadeOnDelete(false);
            HasOptional(p => p.ExecutedBy).WithOptionalDependent().Map(m => m.MapKey("executedbyid")).WillCascadeOnDelete(false);
            HasRequired(p => p.Agent).WithMany().Map(m => m.MapKey("agentid")).WillCascadeOnDelete(false);
            HasRequired(p => p.Payment).WithMany().Map(m => m.MapKey("moneyid")).WillCascadeOnDelete(false);
            Property(x => x.Unique).HasColumnName("number").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            HasRequired(p => p.Agent).WithMany().Map(m => m.MapKey("agentid")).WillCascadeOnDelete(false);
           
        }
    }
}